package za.um.td.entity.mouse;

import java.util.HashMap;
import java.util.Properties;

import org.lex.input.StrategicHandler;
import org.lex.input.effects.HeightMap;
import org.lex.input.mouse.MouseManager;
import org.lex.input.mouse.component.CombinedMouse;

import com.jme.entity.Entity;
import com.jme.renderer.Camera;
import com.jme.scene.Spatial;
import com.jme.system.DisplaySystem;

public class MouseEntity extends Entity {

	private MouseManager mouseManager;
	private Camera camera;

	// Handler for LevelStates
	private StrategicHandler strategicHandler;

	public MouseEntity(String id) {
		this(id, new Properties());
	}

	public MouseEntity(String id, Properties properties) {
		super(id, properties);
		mouseManager = new MouseManager(CombinedMouse.get());

		/*mouseManager.setCursor("defaultCursor",
				"org/lex/cursors/goldenarrow_v2/default.cursor");
		mouseManager.setCursor("attackCursor",
				"org/lex/cursors/goldenarrow_v2/spinning.cursor");
		mouseManager.setCursor("selectCursor",
				"org/lex/cursors/goldenarrow_select/default.cursor");*/
		
		mouseManager.setMousePosition(
				DisplaySystem.getDisplaySystem().getWidth() >> 1,
				DisplaySystem.getDisplaySystem().getHeight() >> 1);

		camera = DisplaySystem.getDisplaySystem().getRenderer().getCamera();
		
		camera.setFrustumFar(2000); //no clipping for the current level, default = 1000 
		
		setSpatial(mouseManager.getMouse().getMouseSpatial());
		getSpatial().setCullHint(Spatial.CullHint.Never);
	}

	public void initStrategicHandler(HeightMap heightMap) {
		strategicHandler = new StrategicHandler(camera, mouseManager, heightMap);
		
		HashMap props = new HashMap();
		
		props.put(StrategicHandler.PROP_MOUSE_SCROLL_MAXSPEED, 80);
		props.put(StrategicHandler.PROP_KEYBOARD_SCROLL_MAXSPEED, 80);
		//props.put(StrategicHandler.PROP_ZOOM_DISTANCE_MIN, 1f);
		props.put(StrategicHandler.PROP_ZOOM_DISTANCE_MAX, 100f);

		strategicHandler.updateProperties(props);

		/*HashMap cursors = new HashMap();
		cursors.put(StrategicHandler.CURSOR_ROTATE,
				"org/lex/cursors/goldenarrow_rotate/default.cursor");
		cursors.put(StrategicHandler.CURSOR_SCROLL_UP,
				"org/lex/cursors/goldenscroll_up/default.cursor");
		cursors.put(StrategicHandler.CURSOR_SCROLL_UPLEFT,
				"org/lex/cursors/goldenscroll_upleft/default.cursor");
		strategicHandler.updateCursors(cursors);*/
	}

	public MouseManager getMouseManager() {
		return mouseManager;
	}

	public StrategicHandler getStrategicHandler() {
		return strategicHandler;
	}

	public Camera getCamera() {
		return camera;
	}

	public void setCamera(Camera camera) {
		this.camera = camera;
	}
}
